package com.briup.mt.service.impl;

import com.briup.mt.bean.Application;
import com.briup.mt.bean.ApplicationExample;
import com.briup.mt.dao.ApplicationMapper;
import com.briup.mt.service.IApplicationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author lijiaojiao
 * @version 1.0
 * @date 2020/12/16 11:18
 */
@Service
public class ApplicationImpl implements IApplicationService {
    @Autowired
    private ApplicationMapper applicationMapper;


    @Override
    public List<Application> query(String name) {
        ApplicationExample example=new ApplicationExample();
        if(!StringUtils.isEmpty(name)){
            example.createCriteria().andNameLike("%" + name + "%");
        }
       return applicationMapper.selectByExample(example);
    }

    @Override
    public void saveOrUpdate(Application application) {
        if (application.getId() == null) {
           applicationMapper.insert(application);
        }else{
            applicationMapper.updateByPrimaryKey(application);
        }

    }

    @Override
    public void deleteById(long id) {
        applicationMapper.deleteByPrimaryKey(id);

    }
}
